<template>
	<view class="pages">
		 <tn-nav-bar :isBack="true" backgroundColor="#4169E1" class="tatils">顶大</tn-nav-bar>
		 <view :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view  @click="dzshow=true" v-if="uinfo.dzid!=null" style="width: 96%;margin: 0 auto;margin-top: 10px;
			box-shadow: 5px 5px 5px 5px rgba(238, 238, 238, 0.5);padding: 10px;background-color: #fff;">
				<view style="height: 36px;line-height: 36px;">
					<text class="tn-icon-map-fill" style="font-size: 30px;"></text>
					<text style="font-weight: 600;margin-left: 5px;font-size: 16px;">猪猪侠:</text>
					<text  style="margin-left: 3px;font-size: 16px;">12312321312312</text>
				</view>
				<view style="height: 36px;line-height: 36px;font-size: 15px;color: #a1a1a1;">
					地址：是否能的就是返回的是课程v啊第四次峰会
				</view>
			</view>
			<view @click="dzshow=true" v-if="uinfo.dzid==null"  style="width: 96%;margin: 0 auto;margin-top: 10px;
			box-shadow: 5px 5px 5px 5px rgba(238, 238, 238, 0.5);padding: 10px;background-color: #fff;">
				<view style="height: 36px;line-height: 36px;font-size: 18px;">请选择收货地址</view>
			</view>
			<view style="width: 98%;margin: 0 auto;margin-top: 10px;padding: 10px;background-color: #fff;">
				<view style="height: 30px;line-height: 30px;">商品列表</view>
				<shopdetail :list="lists" :num="num"></shopdetail>
			</view>
			 <view class="footerfixed">
				 <view style="overflow: hidden;height: 100%;">
				 	<view  style="float: left;width: 100%;height: 100%;line-height: 40px;text-align: right;padding-right: 10px;font-size: 16px;">
						<text style="margin-right: 10px;font-weight: 900;">总价:{{pic}}</text>
						<text @click="addorder" style="padding: 10px;background-color: #ff1a31;color: #fff;border-radius: 10px;">结账</text>
				 	</view>
				 </view>
				 
			 </view>
		 </view>
		 
		 
		 <tn-popup v-model="dzshow" mode="center"  length="60%"  width="700rpx" :borderRadius="20" closeBtn>
		       <view style="padding: 20px;background-color: #e7e7e7;">
				   <view style="text-align: center;font-size: 22px;">地址选择</view>
				   <view style="margin-top: 20px;overflow: auto;height: 400px;">
					   <view  @click="xzdzids(item.id)" :class="item.id==uinfo.dzid?'act':''"
						v-for="(item,index) in dzlist" :key="index" 
						style="width: 100%;box-shadow: 5px 5px 5px 5px rgba(238, 238, 238, 0.5);
					   padding: 5px;background-color: #fff;border-radius: 5px;margin-top: 10px;">
					   	<view style="height: 28px;line-height: 28px;">
					   		<text style="font-weight: 600;margin-left: 5px;font-size: 16px;">猪猪侠:</text>
					   		<text  style="margin-left: 3px;font-size: 16px;">12312321312312</text>
					   	</view>
					   	<view style="height: 36px;line-height: 18px;font-size: 15px;color: #a1a1a1;">
					   		地址：是否能的就是返回的是课程v啊第四次峰会
					   	</view>
					   </view>
				   </view>
			   </view>
		 </tn-popup>
		 
	</view>
</template>

<script>
	import request from '@/request/request.js';
	import shopdetail from '@/components/shopdetail/shopdetail.vue'
	export default {
		components: {
			shopdetail
		},
		data() {
			return {
				uinfo:'',
				lists:[],
				id:'',
				lxtype:'',
				dzlist:[],
				dzinfo:'',
				dzshow:false,
				num:0,
				pic:0
			};
		},
		onLoad(opents) {
			this.getuinfo()
			this.id = opents.id
			this.lxtype = opents.lxtype
			this.num = opents.num
			this.getsplist(opents.id)
			this.getaddress()
		},
		methods:{
			//获取用户信息
			getuinfo(){
				let data = {
					id:uni.getStorageSync('uid')
				}	
				request({
					url:'/Users/getDetail',
					headers: {
						isToken: false,
					},
					method: 'post',
					data: data
				}).then(res => {
					this.uinfo = res.data
					this.getdzdetail(res.data.dzid)
				}).catch(error => {
					that.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
				})
			},
			// 用户地址
			getaddress(){
				let data = {
					uid:uni.getStorageSync('uid')
				}	
				request({
					url:'/Address/getList',
					headers: {
						isToken: false,
					},
					method: 'post',
					data: data
				}).then(res => {
					this.dzlist = res.data
					console.log(res)
				}).catch(error => {
					that.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
				})
			},
			//选中地址详情
			getdzdetail(e){
				let data = {
					id:e,
				}	
				request({
					url:'/Address/getDetail',
					headers: {
						isToken: false,
					},
					method: 'post',
					data: data
				}).then(res => {
					this.dzinfo = res.data
					console.log(res)
				}).catch(error => {
					this.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
				})
			},
			xzdzids(e){
				let data = {
					dzid:e,
					id:uni.getStorageSync('uid')
				}
					console.log(data)
				request({
					url:'/Users/getEdit',
					headers: {
						isToken: false,
					},
					method: 'post',
					data: data
				}).then(res => {
					console.log(res.data)
					this.dzshow = false
					this.getuinfo()
				}).catch(error => {
					this.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
				})
			},
			//下单
			addorder(){
				let data = {
					cid:this.id,
					num:this.num,
					pic:this.pic,
					dzid:this.dzid,
					djpic:this.lists[0].num,
					lxtype:1,
					uid:uni.getStorageSync('uid'),
				}
				request({
					url:'/Orders/getAdd',
					headers: {
						isToken: false,
					},
					method: 'post',
					data: data
				}).then(res => {
					if(res.code==200){
						this.tool.toastTip('下单成功', 'none', 1000)
						 setTimeout(() => {
						     uni.reLaunch({
						     	url:'/pages/orderlist/orderlist'
						     })
						    }, 2000);
					}else{
						this.tool.toastTip(res.message, 'none', 1000)
					}
					console.log(res)
				}).catch(error => {
					that.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
				})
			},
			getsplist(e){
				request({
					url:'/Orders/getsplist',
					headers: {
						isToken: false,
					},
					method: 'post',
					data: {id:e}
				}).then(res => {
					this.lists = res.data
					this.pic = res.data[0].num*this.num
					console.log(res)
				}).catch(error => {
					that.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tatils{
		color: #ffffff;
	}
	.pages{
		background-color: #f5f5f5;
		height: 100%;
	}
	/* 底部tabbar start*/
	.footerfixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		height: 40px;
		z-index: 999;
		background-color: #FFFFFF;
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
	}
	.act{
		border: 1px solid #4093ff;
	}
</style>
